//
//  LXWebViewController.m
//  weizhuan
//
//  Created by lixun on 13-8-6.
//  Copyright (c) 2013年 lixun. All rights reserved.
//

#import "LXWebViewController.h"
#import "AppDelegate.h"
#import "PrefixHeader.pch"
#import "UIImage+GIF.h"
#import "SYViewController.h"
#import "LoginViewController.h"
@interface LXWebViewController ()

@end

@implementation LXWebViewController
{
    UIButton *rightNavBtn;
    
    UIButton *JTbutton;

    
    int height;
    
    UIImageView * myImageView;
    UILabel *Tslabel;
    UIView *AlphabgView;
    
    NSString *PostStr;
    BOOL shouldClose;


}
//@synthesize urlStr = _urlStr;

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    navigationImageView.hidden = YES;
    rightNavBtn.hidden = NO;

//    [self.navigationController setNavigationBarHidden:YES animated:NO];

    if ([self.urlStr containsString:@"Shop/Home/mend/sta"]) {
        [self.navigationController setNavigationBarHidden:YES animated:animated];
        
    }else {
        [self.navigationController setNavigationBarHidden:NO animated:animated];
        
    }
    

}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    rightNavBtn.hidden = YES;
    
//    [self.navigationController setNavigationBarHidden:NO animated:NO];
}
- (void)viewDidLoad
{
    
    [super viewDidLoad];
    if ([self.urlStr isEqualToString:@"http://vpay1.luck8868.com/Turntable/Transaction/cid/2.html"]) {
        self.title = @"";
    }else {
        self.title = self.LXtitle;

    }
    
    self.navigationItem.leftBarButtonItem =[AppUtility getNavBtnItemLefBacktWith:@selector(backNative) andTarget:self];
    
    [self.navigationController.navigationBar setTitleTextAttributes:
     
     @{NSFontAttributeName:[UIFont systemFontOfSize:17],
       
       NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    navigationImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];

    
//    //增加监听，当键盘出现或改变时收出消息
//    [[NSNotificationCenter defaultCenter] addObserver:self
//                                             selector:@selector(keyboardWillShow:)
//                                                 name:UIKeyboardWillShowNotification
//                                               object:nil];
//
//    //增加监听，当键退出时收出消息
//    [[NSNotificationCenter defaultCenter] addObserver:self
//                                             selector:@selector(keyboardWillHide:)
//                                                 name:UIKeyboardWillHideNotification
//                                               object:nil];
    
    self.mytypeArray = [NSMutableArray array];
    [self initNavBtns];
    
    [self initViews];

    PostStr = @"";
    
    shouldClose = NO;
	// Do any additional setup after loading the view.
    
}
- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}
#pragma mark - UINavigationControllerDelegate
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    
    [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}
- (void)initNavBtns {

    self.navigationItem.leftBarButtonItem =[AppUtility getNavBtnItemLefBacktWith:@selector(backNative) andTarget:self];
    //50 50
    
    rightNavBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightNavBtn setFrame:CGRectMake1(243-4, 7, 80, 20)];
    //    rightNavBtn.imageEdgeInsets = UIEdgeInsetsMake(5, 10, 0, 0);
    
    if ([self.mytype isEqualToString:@"zr"]) {
        [rightNavBtn setTitle:@"保存二维码" forState:UIControlStateNormal];
        [NSThread detachNewThreadSelector:@selector(requestZRimageData) toTarget:self withObject:nil];


    }else if ([self.mytype isEqualToString:@"fx"]) {
        [rightNavBtn setTitle:@"保存二维码" forState:UIControlStateNormal];
        [NSThread detachNewThreadSelector:@selector(requestShareimageData) toTarget:self withObject:nil];

    }
    else if ([self.mytype isEqualToString:@"dh"]) {
        [rightNavBtn setTitle:@"兑换记录" forState:UIControlStateNormal];
        
    }
    else if ([self.mytype isEqualToString:@"szzc"]) {
        [rightNavBtn setTitle:@"交易记录" forState:UIControlStateNormal];
    }
    else if ([self.mytype isEqualToString:@"zhongchou"]) {
  
        [rightNavBtn setTitle:@"记录" forState:UIControlStateNormal];

    }else if ([self.mytype isEqualToString:@"zc"]) {
        
        [rightNavBtn setTitle:@"转出记录" forState:UIControlStateNormal];
        
    }
    
    rightNavBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [rightNavBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rightNavBtn addTarget:self action:@selector(rightNavBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationController.navigationBar addSubview:rightNavBtn];
    
    
    JTbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    [JTbutton setFrame:CGRectMake1(150, 7, 20, 20)];
    [JTbutton setImage:[AppUtility getLocalImage:@"DSJ"] forState:UIControlStateNormal];
    JTbutton.imageEdgeInsets = UIEdgeInsetsMake(4, 1, 4, 1);
    JTbutton.hidden = YES;
    [JTbutton addTarget:self action:@selector(JTBtnClicked) forControlEvents:UIControlEventTouchUpInside];

    [self.navigationController.navigationBar addSubview:JTbutton];

    
}
-(void)requestPersonData
{
    
    NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@userid=%@&isApp=1",KURLUserInfo,@""] andPostStr:nil];
    
    UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLUserInfo,resultDict_hot);
    
    if ([[resultDict_hot objectForKey:@"s"] intValue]==1) {
        
//        [userDic removeAllObjects];
//
//        //        [myArray addObjectsFromArray:[resultDict_hot objectForKey:@"d"]];
//        userDic = [[NSMutableDictionary alloc]initWithDictionary:[resultDict_hot objectForKey:@"d"]];
        
    }else if ([[resultDict_hot objectForKey:@"s"] intValue]==303) {
        
        [self.navigationController.view makeToast:resultDict_hot[@"i"]];
        [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWNO];
        [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWPass];
        LoginViewController *vc = [[LoginViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
        return;
    }
    
//    [self performSelectorOnMainThread:@selector(RefreshView) withObject:nil waitUntilDone:NO];
    
}
- (void)leftNavBtnClicked {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)JTBtnClicked {
    AlphabgView.hidden = NO;
    TpyeTableView.hidden = NO;
}
- (void)rightNavBtnClicked {
    if ([self.mytype isEqualToString:@"zc"]) {
        LXWebViewController *vc = [[LXWebViewController alloc]init];
        vc.LXtitle = @"转出记录";
        vc.urlStr = @"http://vpay1.luck8868.com/Index/Turncords.html";
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if ([self.mytype isEqualToString:@"dh"]) {
        LXWebViewController *vc = [[LXWebViewController alloc]init];
        vc.LXtitle = @"兑换记录";
        vc.urlStr = @"http://vpay1.luck8868.com/Index/Exchangerecords.html";
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([self.mytype isEqualToString:@"szzc"]) {
        LXWebViewController *vc = [[LXWebViewController alloc]init];
        vc.LXtitle = @"交易记录";
        vc.urlStr = @"http://vpay1.luck8868.com/Turntable/Trans.html";
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([self.mytype isEqualToString:@"zhongchou"]) {
        LXWebViewController *vc = [[LXWebViewController alloc]init];
        vc.LXtitle = @"记录";
        vc.urlStr = @"http://vpay1.luck8868.com/Turntable/Crowdrecords.html";
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([self.mytype isEqualToString:@"tb"]) {
//        LXWebViewController *vc = [[LXWebViewController alloc]init];
//        vc.LXtitle = @"提币";
//        vc.urlStr = @"http://vpay1.luck8868.com/Turntable/Crowdrecords.html";
//        [self.navigationController pushViewController:vc animated:YES];
    }else if ([self.mytype isEqualToString:@"zr"]) {
//        [self toSaveImage:@"http://vpay1.luck8868.com/Uploads/Rcode/codes408668.png"];
        [self toSaveImage:_myDic[@"url"]];
    }else if ([self.mytype isEqualToString:@"fx"]) {
        //        [self toSaveImage:@"http://vpay1.luck8868.com/Uploads/Rcode/codes408668.png"];
        [self toSaveImage:_ShareDic[@"url"]];
    }
    else if ([self.mytype isEqualToString:@"szzczc"]) {
        
        LXWebViewController *vc = [[LXWebViewController alloc]init];
        vc.LXtitle = @"转出";
        vc.urlStr = @"http://vpay1.luck8868.com/Turntable/Trans.html";
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if ([self.mytype isEqualToString:@"zcxm"]) {
        
        LXWebViewController *vc = [[LXWebViewController alloc]init];
        vc.LXtitle = @"众筹项目记录";
        vc.urlStr = @"http://vpay1.luck8868.com/Turntable/Crowdrecords.html";
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if ([self.mytype isEqualToString:@"zcjl"]) {
        
        LXWebViewController *vc = [[LXWebViewController alloc]init];
        vc.LXtitle = @"转出记录";
        vc.urlStr = @"http://vpay1.luck8868.com/Index/Bancerecord.html";
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([self.mytype isEqualToString:@"tjbank"]) {
        
        LXWebViewController *vc = [[LXWebViewController alloc]init];
        vc.LXtitle = @"区域选择";
        vc.urlStr = @"http://vpay1.luck8868.com/Growth/Arealist.html";
        [self.navigationController pushViewController:vc animated:YES];
    }
}
- (void)initViews{
    
    
    myImageView = [[UIImageView alloc]init];
    myImageView.image = [UIImage sd_animatedGIFNamed:@"load"];
    
    [myImageView setFrame:CGRectMake(self.view.frame.size.width/2-144*theApp.autoSizeScaleX/2, self.view.frame.size.height/2-144*theApp.autoSizeScaleY/2-44*theApp.autoSizeScaleY-40*theApp.autoSizeScaleY, 144.0f*theApp.autoSizeScaleX, 144.0f*theApp.autoSizeScaleY)];
    
    Tslabel = [[UILabel alloc]initWithFrame:CGRectMake(0, myImageView.frame.origin.y+myImageView.frame.size.height+5*theApp.autoSizeScaleY, [AppUtility screenWidth], 30*theApp.autoSizeScaleY)];
    Tslabel.backgroundColor = [UIColor clearColor];
    Tslabel.font = [UIFont systemFontOfSize:14];
    Tslabel.text = @"正在加载......";
    Tslabel.textAlignment = NSTextAlignmentCenter;
    Tslabel.textColor = RGBCOLOR(153, 153, 153);
    
    [self.view addSubview:Tslabel];
    
    [self.view addSubview:myImageView];
    
    _webView =[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, [AppUtility screenWidth], [AppUtility screenHeight]-44*theApp.autoSizeScaleY)];
    _webView.delegate =self;
    _webView.backgroundColor =[UIColor clearColor];
    _webView.dataDetectorTypes = UIDataDetectorTypeNone;

    NSURLRequest *request =[NSURLRequest  requestWithURL:[NSURL URLWithString:self.urlStr]] ;
    [_webView loadRequest:request];
    
    [self.view addSubview:_webView];
    
    AlphabgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [AppUtility screenWidth], [AppUtility screenHeight]-44*theApp.autoSizeScaleY)];
    AlphabgView.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
//    AlphabgView.alpha = 0.5;
    AlphabgView.hidden = YES;
    [self.view addSubview:AlphabgView];
    
    TpyeTableView = [[UITableView alloc]initWithFrame:CGRectMake(78*theApp.autoSizeScaleX, 64*theApp.autoSizeScaleY, 164*theApp.autoSizeScaleX, AlphabgView.frame.size.height-128*theApp.autoSizeScaleY) style:UITableViewStylePlain];
    TpyeTableView.delegate = self;
    TpyeTableView.layer.masksToBounds = YES;
    TpyeTableView.layer.cornerRadius = 4.5;
    TpyeTableView.showsVerticalScrollIndicator = NO;
    TpyeTableView.showsHorizontalScrollIndicator = NO;
    TpyeTableView.dataSource = self;
    TpyeTableView.rowHeight = 35*theApp.autoSizeScaleY;
    TpyeTableView.backgroundColor = BACKCOLOR;
    TpyeTableView.hidden = YES;
//    TpyeTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:TpyeTableView];
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TapCancel)];
    [AlphabgView addGestureRecognizer:tap];
    
}
- (void)TapCancel {
    AlphabgView.hidden = YES;
    TpyeTableView.hidden = YES;

}
//当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)aNotification
{
    //获取键盘的高度
    NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    height = keyboardRect.size.height;
    
    
    UIView *View = (UIView *)[self.view viewWithTag:10];
    
    [View setFrame:CGRectMake1(0, [AppUtility screenHeight]-height-200, [AppUtility screenWidth], 200)];
    UEXNSLog(@"%d",height);
}

//当键退出时调用
- (void)keyboardWillHide:(NSNotification *)aNotification{
    
    UIView *View = (UIView *)[self.view viewWithTag:10];
    
    UIView *alphaView = (UIView *)[self.view viewWithTag:11];
    [View setFrame:CGRectMake1(0, alphaView.frame.origin.x+alphaView.frame.size.height, [AppUtility screenWidth], 200)];
    
}
- (void)toSaveImage:(NSString *)urlString {
    NSURL *url = [NSURL URLWithString: urlString];
    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    UIImage *img;
    if ([manager diskImageExistsForURL:url]) {
        img = [[manager imageCache] imageFromDiskCacheForKey:url.absoluteString];
        
    } else {
        //从网络下载图片
        NSData *data = [NSData dataWithContentsOfURL:url];
        img = [[UIImage alloc]initWithData:data];
//        img = [UIImage imageWithData:data];
        
    } // 保存图片到相册中
    UIImageWriteToSavedPhotosAlbum(img,self, @selector(image:didFinishSavingWithError:contextInfo:),nil);
        
        
        
}
//保存图片完成之后的回调
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    // Was there an error?
    if (error != NULL) {
        // Show error message…
        [self.view makeToast:@"图片保存失败"];
        
    } else // No errors
    { // Show message image successfully saved
        [self.view makeToast:@"图片保存成功"];
        
    }
    
}

-(void)requestZRimageData
{
    
    NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@",KURLZRZbarCode] andPostStr:nil];
    
    UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLZRZbarCode,resultDict_hot);
    
    if ([[resultDict_hot objectForKey:@"s"] intValue]==1) {
        
        [_myDic removeAllObjects];
        
        //        [myArray addObjectsFromArray:[resultDict_hot objectForKey:@"d"]];
        _myDic = [[NSMutableDictionary alloc]initWithDictionary:[resultDict_hot objectForKey:@"d"]];
        
        
    }
    
//    [self performSelectorOnMainThread:@selector(RefreshView) withObject:nil waitUntilDone:NO];
    
}
-(void)requestShareimageData
{
    
    NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@",KURLShareZbarCode] andPostStr:nil];
    
    UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLShareZbarCode,resultDict_hot);
    
    if ([[resultDict_hot objectForKey:@"s"] intValue]==1) {
        
        [_ShareDic removeAllObjects];
        
        //        [myArray addObjectsFromArray:[resultDict_hot objectForKey:@"d"]];
        _ShareDic = [[NSMutableDictionary alloc]initWithDictionary:[resultDict_hot objectForKey:@"d"]];
        
        
    }
    
    //    [self performSelectorOnMainThread:@selector(RefreshView) withObject:nil waitUntilDone:NO];
    
}
-(void)requestTypeData
{
    NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:KURLCoinType andPostStr:PostStr];
    
    UEXNSLog(@"URL = %@%@ ,resultDict_hot=%@",KURLCoinType,PostStr,resultDict_hot);
    
    if ([[resultDict_hot objectForKey:@"s"] intValue]==1) {
        
        [self.mytypeArray removeAllObjects];
        
        [self.mytypeArray addObjectsFromArray:[resultDict_hot objectForKey:@"d"]];
        
        
    }
    
    [self performSelectorOnMainThread:@selector(RefreshView) withObject:nil waitUntilDone:NO];
    
}
#pragma mark -
#pragma mark for delegate
#pragma mark -
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mytypeArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSMutableDictionary *dic = [self.mytypeArray objectAtIndex:indexPath.row] ;
    UITableViewCell *cell = nil;
    UITableViewCell *cell1 = [TpyeTableView dequeueReusableCellWithIdentifier:@"TypeTableViewCell"];
    if (!cell1)
    {
        cell1 = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TypeTableViewCell"];
        cell1.backgroundColor = [UIColor whiteColor];
        
        UILabel *typelabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, TpyeTableView.frame.size.width, 35*theApp.autoSizeScaleY)];
        typelabel.font = [UIFont systemFontOfSize:14];
        typelabel.textAlignment = NSTextAlignmentCenter;
        typelabel.textColor = [UIColor blackColor];
        typelabel.backgroundColor = [UIColor clearColor];
        typelabel.tag = 10;
        [cell1.contentView addSubview:typelabel];
    }
    UILabel *typelabel = (UILabel *)[cell1.contentView viewWithTag:10];
    typelabel.text = dic[@"coinName"];
    
    cell1.selectionStyle = UITableViewCellSelectionStyleNone;
    //    [cell1 SetCellInfo:dic];
    
    cell = cell1;
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    AlphabgView.hidden = YES;
    TpyeTableView.hidden = YES;

    NSURLRequest *request =[NSURLRequest  requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.mytypeArray[indexPath.row][@"url"]]]] ;
    [_webView loadRequest:request];
    
//    LXWebViewController *vc = [[LXWebViewController alloc]init];
////    vc.LXtitle = @"众筹项目中心";
////    vc.mytype = @"zhongchou";
//    vc.urlStr = self.mytypeArray[indexPath.row][@"url"];
//    [self.navigationController pushViewController:vc animated:YES];
}
    


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    
    NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@userid=%@&isApp=1",KURLUserInfo,@""] andPostStr:nil];
    
    UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLUserInfo,resultDict_hot);
    
    if ([resultDict_hot[@"s"] intValue] == 303) {
        [self.navigationController.view makeToast:resultDict_hot[@"i"]];
        
        [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWNO];
        [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWPass];
        
        LoginViewController *vc = [[LoginViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
        
        return NO;
        
    }
    //    self.hud.hidden =NO;
    myImageView.hidden = NO;
    Tslabel.hidden = NO;
    _webView.hidden =YES;
    
    NSString *url = request.URL.absoluteString;
    SLog(@"url=%@",url);
    SLog(@"url=%@",request.URL.relativeString);
    
    if ([url containsString:@"Index/exehange.html"]) {
        
        self.LXtitle = @"兑换资产";
        [rightNavBtn setTitle:@"兑换记录" forState:UIControlStateNormal];
        self.mytype = @"dh";
        
        
    }else if ([url containsString:@"Turntable/index.html"]) {
        
        self.navigationItem.leftBarButtonItem =[AppUtility getNavBtnItemLefBacktWith:@selector(leftNavBtnClicked) andTarget:self];
        
        self.LXtitle = @"数字资产";
        [rightNavBtn setTitle:@"交易记录" forState:UIControlStateNormal];
        [self.navigationController setNavigationBarHidden:NO animated:NO];
        
        rightNavBtn.hidden = NO;
        JTbutton.hidden = YES;
        self.mytype = @"szzc";
        
        
        
    } else if ([url containsString:@"Turntable/Transaction/cid"]) {
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        
    }else if ([url containsString:@"Turncoindets/Transaction/cid"]) {
        
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        
        
        
    }else if ([url containsString:@"Index/turnout.html"]) {
        [rightNavBtn setTitle:@"转出记录" forState:UIControlStateNormal];
        self.mytype = @"zc";
        
        
    }else if ([url containsString:@"Changeout/sid"]) {
        [rightNavBtn setTitle:@"转出记录" forState:UIControlStateNormal];
        self.mytype = @"zcjl";
        shouldClose = YES;
        
        
    }else if ([url containsString:@"Index/index"]||[url containsString:@"index/index"]) {

        if (shouldClose == YES) {
            for (UIViewController *controller in self.navigationController.viewControllers) {
                if ([controller isKindOfClass:[SYViewController class]]) {
                    SYViewController *messageVC =(SYViewController *)controller;
                    [self.navigationController popToViewController:messageVC animated:YES];
                }
            }
            [self.navigationController popViewControllerAnimated:YES];
            
        }else {
            
        }
        
        
    }else if ([url containsString:@"Shop/dianpu/dp_info"]) {
//        shouldClose = YES;
        [self.navigationController setNavigationBarHidden:NO animated:NO];
        
        
        
    }else if ([url containsString:@"Shop/member/mine"]) {
//        shouldClose = YES;
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        
        
        
    }else if ([url containsString:@"Shop/Member/mine"]) {
//        shouldClose = YES;
        self.LXtitle = @"";
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        
        
        
    }else if ([url containsString:@"shop/member/mine"]) {
//        shouldClose = YES;
        self.LXtitle = @"";
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        
        
        
    }else if ([url containsString:@"Shop/Home/index"]) {
        shouldClose = YES;
        self.LXtitle = @"";
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        
        
        
    }
    //    else if ([url containsString:@"Shop/Home/index"]) {
    //
    ////        if (shouldClose == YES) {
    ////            //            for (UIViewController *controller in self.navigationController.viewControllers) {
    ////            //                if ([controller isKindOfClass:[SYViewController class]]) {
    ////            //                    SYViewController *messageVC =(SYViewController *)controller;
    ////            //                    [self.navigationController popToViewController:messageVC animated:YES];
    ////            //                }
    ////            //            }
    ////            [self.navigationController popViewControllerAnimated:YES];
    ////
    ////        }else {
    ////
    ////        }
    ////        [self.navigationController setNavigationBarHidden:YES animated:NO];
    //
    //
    //
    //    }else if ([url caseInsensitiveCompare:@"shop/home/index"]) {
    //
    ////        if (shouldClose == YES) {
    ////            //            for (UIViewController *controller in self.navigationController.viewControllers) {
    ////            //                if ([controller isKindOfClass:[SYViewController class]]) {
    ////            //                    SYViewController *messageVC =(SYViewController *)controller;
    ////            //                    [self.navigationController popToViewController:messageVC animated:YES];
    ////            //                }
    ////            //            }
    ////            [self.navigationController popViewControllerAnimated:YES];
    ////
    ////        }else {
    ////
    ////        }
    ////        [self.navigationController setNavigationBarHidden:YES animated:NO];
    //
    //    }
    else if ([url containsString:@"Turntable/Salesell/cid"]||[url containsString:@"Turntable/Salebuys/cid"]) {
        
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        
    }
    
    else if ([url containsString:@"Turntable/Transaction/cid"]) {
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        
    }
    
    
    else if ([url containsString:@"Turncoindets/Orderinfos/cid"]||[url containsString:@"Turntable/Orderinfos/cid"]) {
        
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        
        
        
    }
    else if ([url containsString:@"Tibi/index.html"]) {
        self.navigationItem.leftBarButtonItem =[AppUtility getNavBtnItemLefBacktWith:@selector(backNative) andTarget:self];
        
        self.LXtitle = @"提币";
        [rightNavBtn setTitle:@"记录" forState:UIControlStateNormal];
        self.mytype = @"tb";
        
    }else if ([url containsString:@"Growth/Introrecords"]) {
        self.LXtitle = @"转入记录";
        rightNavBtn.hidden = YES;
        
    }
    else if ([url containsString:@"Turntable/Turnout.html"]) {
        self.navigationItem.leftBarButtonItem =[AppUtility getNavBtnItemLefBacktWith:@selector(backNative) andTarget:self];
        
        self.LXtitle = @"转出";
        [rightNavBtn setTitle:@"记录" forState:UIControlStateNormal];
        self.mytype = @"szzczc";
        
    }else if ([url containsString:@"Turntable/Trans.html"]) {
        self.navigationItem.leftBarButtonItem =[AppUtility getNavBtnItemLefBacktWith:@selector(backNative) andTarget:self];
        
        self.LXtitle = @"交易记录";
        //        self.mytype = @"szzczc";
        
    }
    else if ([url containsString:@"Turntable/Crowds.html"]) {
        self.navigationItem.leftBarButtonItem =[AppUtility getNavBtnItemLefBacktWith:@selector(backNative) andTarget:self];
        
        self.LXtitle = @"众筹项目中心";
        [rightNavBtn setTitle:@"记录" forState:UIControlStateNormal];
        self.mytype = @"zcxm";
        
    }
    else if ([url containsString:@"Turntable/Wbaobei.html"]) {
        self.navigationItem.leftBarButtonItem =[AppUtility getNavBtnItemLefBacktWith:@selector(backNative) andTarget:self];
        
        self.LXtitle = @"V宝数字中心";
        rightNavBtn.hidden = YES;
        //        self.mytype = @"zcxm";
        
    } else if ([url containsString:@"Shop/Member/address.html"]||[url containsString:@"Shop/Member/Dditadd/id"]) {
        self.LXtitle = @"收货地址";
        rightNavBtn.hidden = YES;
        //        self.mytype = @"zcxm";
        
    }else if ([url containsString:@"Growth/Purchase/cid"]) {
        self.LXtitle = @"买入";
        rightNavBtn.hidden = YES;
        //        self.mytype = @"zcxm";
        
    }
    else if ([url containsString:@"Growth/Nofinsh.html"]) {
        self.LXtitle = @"未完成订单";
        rightNavBtn.hidden = YES;
        //        self.mytype = @"zcxm";
        
    }
    else if ([url containsString:@"Growth/Conpay.html"]) {
        self.LXtitle = @"确认打款";
        rightNavBtn.hidden = YES;
        //        self.mytype = @"zcxm";
        
    }else if ([url containsString:@"Growth/Dofinsh.html"]) {
        self.LXtitle = @"已完成订单";
        rightNavBtn.hidden = YES;
        //        self.mytype = @"zcxm";
        
    }else if ([url containsString:@"Growth/Buyrecords.html"]) {
        self.LXtitle = @"买入记录";
        rightNavBtn.hidden = YES;
        //        self.mytype = @"zcxm";
        
    }
    else if ([url containsString:@"Growth/Buycenter.html"]) {
        self.LXtitle = @"买入中心";
        rightNavBtn.hidden = YES;
        //        self.mytype = @"zcxm";
        
    }else if ([url containsString:@"User/Teamdets"]) {
        self.LXtitle = @"分享记录";
        rightNavBtn.hidden = YES;
        //        self.mytype = @"zcxm";
        
    } else if ([url containsString:@"Growth/Addbank"]) {
        self.LXtitle = @"添加银行卡";
        //        [rightNavBtn setTitle:@"中国" forState:UIControlStateNormal];
        rightNavBtn.hidden = YES;
        self.mytype = @"tjbank";
        
    }
    else if ([url containsString:@"Growth/Cardinfos"]) {
        self.LXtitle = @"我的银行卡";
        [self.navigationController setNavigationBarHidden:NO animated:NO];
        
    }
    
    //我的店铺
    else if ([url containsString:@"Shop/Member/addresslist"]) {
        self.LXtitle = @"地址管理";
        [self.navigationController setNavigationBarHidden:NO animated:NO];
        
        
    }else if ([url containsString:@"Shop/member/addresslist"]) {
        self.LXtitle = @"地址管理";
        [self.navigationController setNavigationBarHidden:NO animated:NO];
        
        
    }
    else if ([url containsString:@"shop/home/Minepros"]) {
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        
    }else if ([url containsString:@"Shop/Home/Business"]) {
        self.LXtitle = @"产品上传";
        [self.navigationController setNavigationBarHidden:NO animated:NO];
        
        
    }else if ([url containsString:@"Shop/Member/Mineorders"]||[url containsString:@"Shop/Member/allorder/s"]||[url containsString:@"Shop/Member/allorder"]) {
        self.LXtitle = @"我的订单";
        [self.navigationController setNavigationBarHidden:NO animated:NO];
        
        
    }
    else if ([url containsString:@"Shop/Member/orderInfo/id"]) {
        
        self.LXtitle = @"订单详情";
        [self.navigationController setNavigationBarHidden:NO animated:NO];
        
        
    }
    else if ([url containsString:@"Shop/Home/details/proid/"]) {
        
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        
        
    }else if ([url containsString:@"Turntable/exehange.html"]) {
        
        self.LXtitle = @"兑换USDT";
        rightNavBtn.hidden = YES;
        [self.navigationController setNavigationBarHidden:NO animated:NO];
        
        
    }
    
    //商城
    
    else if ([url containsString:@"Shop/Home/mend/sta"]) {
        
        //        self.LXtitle = @"订单详情";
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        shouldClose = YES;
        
        
    }
    
    self.title = self.LXtitle;
    return YES;
    
}


- (void)webViewDidFinishLoad:(UIWebView *)webView {
    
    if (self.navigationController.navigationBar.hidden == YES) {
        _webView.frame = CGRectMake(0, 0, [AppUtility screenWidth], [AppUtility screenHeight]);
        
    }else {
        _webView.frame = CGRectMake(0, 0, [AppUtility screenWidth], [AppUtility screenHeight]-44*theApp.autoSizeScaleY);
        
    }
    
    [self performSelector:@selector(hidenaction)withObject:self afterDelay:0.1];
    
    
    
}
- (void)RefreshView {
    [TpyeTableView reloadData];
}
- (void)hidenaction{
    
    /// 开始加载时隐藏webview 加载完后显示，原因是 因为我们要去掉头标签，，去掉的方法是在网页加载完毕进行的，，添加一个延时现实的方法 可以隐藏掉网页先显示头标签又被移除的过程。使其看起来更自然一些
    
    _webView.hidden =NO;
    
    myImageView.hidden =YES;
    Tslabel.hidden = YES;
    
}
////用于授权验证的API，与AFN、UIWebView的授权验证API是一样的
//- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *__nullable credential))
//
//    completionHandler{ completionHandler(NSURLSessionAuthChallengePerformDefaultHandling ,nil);
//
//}
//
//
//
//// 页面开始加载时调用
//-(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
//
////    [self.navigationController setNavigationBarHidden:YES animated:YES];
//    SLog(@"开始加载");
// }
//// 当内容开始返回时调用
//- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
//
////    [self.navigationController setNavigationBarHidden:YES animated:YES];
//    SLog(@"内容开始返回");
//
//}
//// 页面加载完成之后调用
//- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
//    //这里修改导航栏的标题，动态改变
////    [self.navigationController setNavigationBarHidden:YES animated:YES];
//
////    self.title = webView.title;
//    SLog(@"加载完成");
//
//    [webView evaluateJavaScript:@"document.getElementsByClassName('page-header')[0].style.display='none'" completionHandler:nil];
//
//}
//- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
////    [self.navigationController setNavigationBarHidden:YES animated:YES];
//
//}
//// 页面加载失败时调用
//- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation{ }
//// 接收到服务器跳转请求之后再执行
//- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation{ }
//// 在收到响应后，决定是否跳转
//- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{
//    SLog(@"%@",webView);
//    SLog(@"%@",navigationResponse);
//    WKNavigationResponsePolicy actionPolicy = WKNavigationResponsePolicyAllow;
//    //这句是必须加上的，不然会异常
//    decisionHandler(actionPolicy);
//
//}
//// 在发送请求之前，决定是否跳转
//- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
//    WKNavigationResponsePolicy actionPolicy = WKNavigationResponsePolicyAllow;
//    //这句是必须加上的，不然会异常
//    decisionHandler(actionPolicy);
//}


#pragma mark -event

- (void)backNative {
    if ([_webView canGoBack]) {
        [_webView goBack];
    }else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}
//-(void)leftNavBtnClicked{
//    [self.navigationController popViewControllerAnimated:YES];
////    [theApp showBottomView];
//}
//-(void)rightNavBtnClicked{
//    if (_webView) {
//        [_webView reload];
//    }
//}
//-(void)preBtnClicked:(UIButton*)_inBtn{
//    //
//}
//-(void)nextBtnClicked:(UIButton*)_inBtn{
//
//}
//-(void)refreshBtnClicked:(UIButton*)_inBtn{
//    [_webView reload];
//}
//-(void)webViewDidStartLoad:(UIWebView *)webView{
//    [_refreshBtn setEnabled:NO];
//    [AppUtility showNetworkActivityIndicator:YES];
//}
//
//-(void)webViewDidFinishLoad:(UIWebView *)webView{
//    [_refreshBtn setEnabled:YES];
//     [AppUtility showNetworkActivityIndicator:NO];
//    if ([_webView canGoBack]) {
//        [_preBtn setEnabled:YES];
//    }else{
//         [_preBtn setEnabled:NO];
//    }
//    if ([_webView canGoBack]) {
//        [_preBtn setEnabled:YES];
//    }else{
//        [_preBtn setEnabled:NO];
//    }
//
//}

@end
